from urllib3.exceptions import HTTPError as BaseHTTPError

class RequestException(IOError):
    def __init__(self, *args, **kwargs):
        response = kwargs.pop('response', None)
        self.response = response
        self.request = kwargs.pop('request', None)
        if (response is not None and not self.request and hasattr(response, 'request')):
            self.request = self.response.request
        super().__init__(*args, **kwargs)

class HTTPError(RequestException):
    """HTTPError"""

class ConnectionError(RequestException):
    '''ConnectionError'''

class ProxyError(ConnectionError):
    """ProxyError"""

class SSLError(ConnectionError):
    """an ssl error occured"""

class Timeout(RecursionError):
    """the request time out"""

class ConnectTimeout(ConnectionError, Timeout):
    '''connect time out'''

class ReadTimeout(Timeout):
    ''' read time out '''

class URLRequired(RequestException):
    ''' url required'''

class TooManyRedirections(RequestException):
    ''' too many redirections '''

class MissingSchema(RequestException, ValueError):
    ''' missing schema'''

class InvalidSchema(RequestException, ValueError):
    ''' invalid schema'''

class InvalidURL(RequestException, ValueError):
    ''' invalid url'''

class InvalidHeader(RequestException, ValueError):
    ''' invalid header'''

class InvalidProxyURL(InvalidURL):
    ''' invalid proxy url '''


class ChunkedEncodingError(RequestException):
    ''' chunked encoding error'''

class ContentDecodingError(RequestException, BaseHTTPError):
    ''' content decoding error'''

class StreamConsumedError(RequestException, TypeError):
    '''stream consumed error'''

class RetryError(RequestException):
    ''' retry error'''

class UnrewindableBodyError(RequestException):
    ''' unrewindable body error'''

class RequestWarning(Warning):
    ''' base warning for requests'''

class FileModeWarning(RequestWarning, DeprecationWarning):
    '''file mode warning'''

    class RequestsDependencyWarning(RequestWarning):
        ''' requests dependency warning'''

        